import request from '@/utils/request'
import type { ResponseData } from '@/utils/request'

export interface NewsItem {
  id: string
  title: string
  content: string
  publishDate: string
  author: string
  category: string
  tags?: string[]
  thumbnail?: string
}

export interface NewsQueryParams {
  page: number
  pageSize: number
  category?: string
  keyword?: string
  startDate?: string
  endDate?: string
}

/**
 * Get news list with pagination
 */
export function getNewsList(params: NewsQueryParams) {
  return request<ResponseData<{
    list: NewsItem[]
    total: number
  }>>({
    url: '/news/list',
    method: 'get',
    params
  })
}

/**
 * Get news detail by id
 */
export function getNewsDetail(id: string) {
  return request<ResponseData<NewsItem>>({
    url: `/news/detail/${id}`,
    method: 'get'
  })
}

/**
 * Get news categories
 */
export function getNewsCategories() {
  return request<ResponseData<string[]>>({
    url: '/news/categories',
    method: 'get'
  })
}

/**
 * Add news
 */
export function addNews(data: Omit<NewsItem, 'id'>) {
  return request({
    url: '/news/add',
    method: 'post',
    data
  })
}

/**
 * Update news
 */
export function updateNews(data: NewsItem) {
  return request({
    url: '/news/update',
    method: 'put',
    data
  })
}

/**
 * Delete news
 */
export function deleteNews(id: string) {
  return request({
    url: `/news/delete/${id}`,
    method: 'delete'
  })
} 